from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
import time

service = webdriver.ChromeService('./chromedriver.exe')
driver = webdriver.Chrome(service=service)

driver.get('https://seleniumbase.io/demo_page/')
driver.execute_script('''(function() {
    // 创建小红点元素
    const dot = document.createElement('div');
    dot.style.cssText = `
        position: fixed;
        width: 10px;
        height: 10px;
        background: red;
        border-radius: 50%;
        pointer-events: none;
        z-index: 9999;
        display: none;
    `;
    document.body.appendChild(dot);

    // 鼠标移动事件
    let timeout;
    document.addEventListener('mousemove', function(e) {
        // 显示小红点
        dot.style.display = 'block';
        dot.style.left = e.clientX - 5 + 'px';
        dot.style.top = e.clientY - 5 + 'px';

        // 清除之前的定时器
        clearTimeout(timeout);

        // 1秒后隐藏小红点
        timeout = setTimeout(() => {
            dot.style.display = 'none';
        }, 1000);
    });

    // 鼠标离开页面时隐藏
    document.addEventListener('mouseleave', function() {
        dot.style.display = 'none';
    });
})();''')

myButton = driver.find_element(By.ID, 'myButton')
myButton.click()
mySlider = driver.find_element(By.ID, 'mySlider')
mySlider.click()
ac = ActionChains(driver)
ac.drag_and_drop_by_offset(mySlider,16*(-4),0).click_and_hold()
ac.perform()
myDropdown = driver.find_element(By.ID, 'myDropdown')
myDropdown.screenshot('./static/myDropdown.png')

time.sleep(5)
driver.quit()
